﻿'Params
'tag (Required) : The tag name
'limit (Optional) : The number of results to fetch per page. Defaults to 50.
'page (Optional) : The page number to fetch. Defaults to first page.
'api_key (Required) : A Last.fm API key.
'Auth
'This service does not require authentication. 

Public Structure TagGetTopTracksResponse
    Public tracks() As Track
End Structure

Public Class TagGetTopTracks
    Inherits BaseRequest

    Dim tag As String = ""
    Dim page As String = ""
    Dim limit As String = ""

	Public xmlresponse As XDocument = Nothing

    Public Sub New(tag As String, limit As String, page As String)
        Me.tag = tag
        Me.page = page
        Me.limit = limit

    End Sub

	Public Sub sendRequest()
        InitializeMembers("tag.getTopTracks")

        AddMember("tag", Tag, True)
        AddMember("page", page, False)
        AddMember("limit", limit, False)
        AddMember("api_key", My.Settings.api_key, False)
        xmlresponse = sendPOSTResponse()
	End Sub

    Public Function getResponse() As TagGetTopTracksResponse
        Dim response As New TagGetTopTracksResponse
        Dim count As Integer

        Try
            count = xmlresponse.<lfm>.<toptracks>.Count()   'tag
        Catch ex As Exception
            Return response
        End Try
        If (count > 0) Then
            ReDim response.tracks(count - 1)
            For i As Integer = 0 To count - 1
                response.tracks(i) = New Track(xmlresponse.<lfm>.<toptracks>(i))
            Next
        End If

        Return response
    End Function
End Class
